package com.uchengwang.ui.cm_ui.uu.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.functions.http.config.BaseConfig;
import com.uchengwang.ui.UChengApplication;
import com.uchengwang.ui.cm_ui.me.bean.UniFeedbackBean;
import com.uchengwang.ui.cm_ui.uu.bean.FeedbackBean;
import com.uchengwang.ui.utils.DateUtil;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2017/8/17.
 */

public class FeedbackResponseAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context context;

    private List<FeedbackBean> list = new ArrayList<>();//普通用户反馈
    private List<UniFeedbackBean> feedbackList = new ArrayList<>();//uni反馈
    private int type;//1普通,社团用户 2uni反馈

    public FeedbackResponseAdapter(Context context, List<FeedbackBean> list, int type){
        this.context = context;
        this.list = list;
        this.type = type;
    }
    public FeedbackResponseAdapter(Context context, int type){
        this.context = context;
        this.type = type;
    }

    public void setData(List<UniFeedbackBean> list){
        this.feedbackList = list;
        notifyDataSetChanged();
    }

    public List<UniFeedbackBean> getData(){
        return feedbackList;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_cmt_msg, parent, false);
        return new FeedbackVH(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder h, int position) {
        FeedbackResponseAdapter.FeedbackVH holder = (FeedbackVH) h;

        switch (UChengApplication.userRole){
            case BaseConfig.UNI_ROLE:
            case BaseConfig.EDITOR_ROLE:
            case BaseConfig.ZONG_ROLE:
                UniFeedbackBean feedbackBean = feedbackList.get(position);
                holder.time.setText(DateUtil.getDateUtil().getTimeStringDate(feedbackBean.getCreateTime()));
                holder.content.setText(feedbackBean.getAdminResponse());

                break;
            default:
                FeedbackBean bean = list.get(position);
                holder.time.setText(DateUtil.getDateUtil().getTimeStringDate(bean.getCreateTime()));
                holder.content.setText(bean.getResponseMsg());
                break;
        }


    }

    @Override
    public int getItemCount() {
        int size = 0;
        switch (type){
            case 1:
                if (list != null){
                    size = list.size();
                }
                break;
            case 2:
                if (feedbackList != null){
                    size = feedbackList.size();
                }
                break;
        }
        return size;
    }

    class FeedbackVH extends RecyclerView.ViewHolder{
        private View itemView;
        private TextView time, content;

        public FeedbackVH(View view) {
            super(view);

            AutoUtils.autoSize(view);
            itemView = view;

            time = (TextView) view.findViewById(R.id.cmtMsg_time);
            content = (TextView) view.findViewById(R.id.cmtMsg_content);

        }







    }
}
